package com.invest.utils.date;


import java.util.Date;

/**
 * populate a date from  String to Date
 * @copyright evan
 * @author evan
 * @Revision
 * @date 2012/8/18
 */
public class DateHelperBuilder {
	
	private Date date;
	private DateHelperBuilder(final Date date) {
		this.date = new Date(date.getTime());
	}
	/**
	 * get instance
	 * @param date
	 * @return
	 */
	public final static DateHelperBuilder instance(Date date) {
		if(null == date){
			throw new RuntimeException("日期不能为空");
		}
		return new DateHelperBuilder(date);
	}
	
	public Date toDate(){
		return date;
	}
	
	/**
	 * get Monday 
	 * @param date
	 * @return
	 */
	public DateHelperBuilder getMonday(){
		date = DateHelper.getMonday(date);
		return this;
	}
	
	/**
	 * get Sunday 
	 * @param date
	 * @return
	 */
	public DateHelperBuilder getSunday(){
		date = DateHelper.getSunday(date);
		return this;
	}
	
	/**
	 * 
	 * @param date
	 * @param week
	 * @return
	 */
	public DateHelperBuilder getWeekByAdjust(WeekType week){
		date = DateHelper.getWeekByAdjust(date,week);
		return this;
	}
	
	/**
	 * add some years
	 * @param date
	 * @param years
	 * @return
	 */
	public DateHelperBuilder addYears(int years){
		date = DateHelper.addYears(date,years);
		return this;
	}
	/**
	 * add some month
	 * @param date
	 * @param month
	 * @return
	 */
	public DateHelperBuilder addMonths(int month){
		date = DateHelper.addMonths(date,month);
		return this;
	}
	
	/**
	 * 
	 * @param date
	 * @param week
	 * @return
	 */
	public DateHelperBuilder addWeeks(int week) {
		date = DateHelper.addWeeks(date,week);
		return this;
	}
	
	/**
	 * add some day
	 * @param date
	 * @param day
	 * @return
	 */
	public DateHelperBuilder addDays(int day) {
		
		date = DateHelper.addDays(date,day);
		return this;
	}
	
	/**
	 * add some hours
	 * @param date
	 * @param hour
	 * @return
	 */
	public DateHelperBuilder addHours(int hour) {

		date = DateHelper.addHours(date,hour);
		return this;
	}


	/**
	 * add some minute
	 * @param date
	 * @param min
	 * @return
	 */
	public DateHelperBuilder addMinutes(int min) {

		date = DateHelper.addMinutes(date,min);
		return this;
	}

	/**
	 * 
	 * @param date
	 * @param sec
	 * @return
	 */
	public DateHelperBuilder addSeconds(int sec) {

		date = DateHelper.addSeconds(date,sec);
		return this;
	}

	
	/**
	 * the begin point of this day
	 * @param date
	 * @param pattern
	 * @return
	 */
	public DateHelperBuilder toBeginPointDay() {

		date = DateHelper.toBeginPointDay(date);
		return this;

	}
	
	/**
	 * to time 8:30 AM from initial time
	 * 
	 * @return
	 */
	public DateHelperBuilder toTime830() {
		
		date = DateHelper.toTime830(date);
		return this;
		
	}
	
	/**
	 * the noon point of this day
	 * @return
	 */
	public DateHelperBuilder toMiddlePointDay() {

		date = DateHelper.toMiddlePointDay(date);
		return this;

	}
	
	/**
	 * the end point of this day
	 * @return
	 */
	public DateHelperBuilder toEndPointDay() {

		date = DateHelper.toEndPointDay(date);
		return this;
	}

	
	/**
	 * first day of this year
	 * @param date
	 * @return
	 */
	public DateHelperBuilder toYearBegin() {
		date = DateHelper.toYearBegin(date);
		return this;
	}

	/**
	 * last day of year
	 * @return
	 */
	public DateHelperBuilder toYearEnd() {
		date = DateHelper.toYearEnd(date);
		return this;
	}
	
	/**
	 * first day of month
	 * @return
	 */
	public DateHelperBuilder toMonthBegin() {
		
		date = DateHelper.toMonthBegin(date);
		return this;
	}

	/**
	 * last day of month
	 * @return
	 */
	public DateHelperBuilder toMonthEnd() {
		
		date = DateHelper.toMonthEnd(date);
		return this;
	}
	
	/**
	 * first day of this week
	 * @return
	 */
	public DateHelperBuilder toWeekBegin() {

		date = DateHelper.toWeekBegin(date);
		return this;

	}
	
	/**
	 * last day of this week
	 * @return
	 */
	public DateHelperBuilder toWeekEnd(){
		date = DateHelper.toWeekEnd(date);
		return this;
	}
}
